//
//  IdentifyBtnPartialView.m
//  ios-supplier
//
//  Created by feynmanyuan on 15/4/20.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "IdentifyBtnPartialView.h"
#import "JFBUIAnimation.h"

@interface IdentifyBtnPartialView()
@property (weak, nonatomic) IBOutlet UIButton *okBtn;
@property (weak, nonatomic) IBOutlet UITextField *identifyTextField;
- (IBAction)veifyAction:(id)sender;
//@property (weak, nonatomic) IBOutlet UIButton *refuseBtn;
- (IBAction)refuseAction:(id)sender;

@end

@implementation IdentifyBtnPartialView

- (void)setOrder:(JFBOrderDS*)order{
    [self setBackgroundColor:[UIColor whiteColor]];
    
    CGRect refuseRect = CGRectMake(0, 0, self.bounds.size.width / 4, cDetailBottomHeight);
//    self.refuseBtn.frame = refuseRect;
//    [self.refuseBtn setBackgroundColor:UIColorFromRGB(0xF1F2F6)];
    
//    CGRect identifyRect = CGRectMake(refuseRect.size.width, 0, self.bounds.size.width * 0.75 - refuseRect.size.width, cDetailBottomHeight);
    CGRect identifyRect = CGRectMake(0, 0, self.bounds.size.width - refuseRect.size.width, cDetailBottomHeight);
    self.identifyTextField.frame = identifyRect;
    [self.identifyTextField setBackgroundColor:[UIColor whiteColor]];
    [self.identifyTextField setPlaceholder:@"输入【收货码】"];
    [self.identifyTextField setBorderStyle:UITextBorderStyleNone];
    self.identifyTextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, cDetailBottomHeight)];
    self.identifyTextField.leftViewMode = UITextFieldViewModeAlways;
    self.identifyTextField.font = [UIFont systemFontOfSize:15];
    
    CGRect okRect = CGRectMake(self.bounds.size.width * 0.75, 0, self.bounds.size.width / 4, cDetailBottomHeight);
    self.okBtn.frame = okRect;
    self.okBtn.titleLabel.textColor = [UIColor whiteColor];
    [self.okBtn setBackgroundColor:ButtonBgColorImportant];
    
    self.height = cDetailBottomHeight;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (IBAction)veifyAction:(id)sender {
    if( [NSString isNilOrEmptyOrWhitespace:self.identifyTextField.text] ) {
        [JFBUIAnimation errorInputTips:self.identifyTextField animation:TipsRock];
        return;
    }
//    [self.identifyTextField resignFirstResponder];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"orderDetailForAction" object:self userInfo:[NSDictionary dictionaryWithObjects:@[self.identifyTextField.text, @"verify"] forKeys:@[@"code", @"event"]]];
}

-( void )triggerNotification:(NSString*)event{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"orderDetailForAction" object:self userInfo:[NSDictionary dictionaryWithObject:event forKey:@"event"]];
}


- (IBAction)refuseAction:(id)sender {
    NSLog(@"refuse");
    [self triggerNotification:@"refuse"];
}
@end
